package dk.eal.kbr.mule.component.exchange;

import org.mule.api.MuleEventContext;
import microsoft.exchange.webservices.data.ExchangeCredentials;
import microsoft.exchange.webservices.data.ExchangeService;
import microsoft.exchange.webservices.data.WebCredentials;

public abstract class ExchangeProxy implements org.mule.api.lifecycle.Callable {

	@Override
	public Object onCall(MuleEventContext eventContext) throws Exception {
		ExchangeCalenderItem calenderItem = (ExchangeCalenderItem) eventContext
				.transformMessage(ExchangeCalenderItem.class);

		return doWork(calenderItem);
	}

	public abstract ExchangeCalenderItem doWork(
			ExchangeCalenderItem calenderItem) throws Exception;

	protected ExchangeService connect(String userEmail, String password)
			throws Exception {
		ExchangeService service = new ExchangeService();
		ExchangeCredentials credentials = new WebCredentials(userEmail,
				password);
		service.setCredentials(credentials);
		service.autodiscoverUrl(userEmail);

		return service;
	}

}
